package com.cdtye.shuoh.util.http;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import com.cdtye.shuoh.config.netty.ServerHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.bind.DatatypeConverter;
import java.io.IOException;


public class HttpRestUtils {
    /**
     * http post
     * */
    public static String post(String url, JSONObject params, String userName, String password) throws IOException {
        String encoding = DatatypeConverter.printBase64Binary((userName+":"+password).getBytes("UTF-8"));
        String result =  HttpRequest.post(url)
                .header("Content-Type", "application/json;charset=UTF-8")
                .header("Authorization","Basic " + encoding)
                .body(params.toString())
                .execute().body();
        return result;
    }


}
